﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'P_GetBasicReferenceTerminals')
	BEGIN
		DROP  Procedure  esf_sso.P_GetBasicReferenceTerminals
	END
GO

CREATE Procedure esf_sso.P_GetBasicReferenceTerminals
	@pBasicReferenceID BIGINT
AS
	
	SELECT 
		DISTINCT VT.ID AS ID
		,VT.Code AS Code
	FROM
		esf_sso.VTerminal VT
	INNER JOIN
		esf_sso.TreeBasicReference TBR ON BasicReferenceID = VT.ID
	WHERE
		TBR.ParentBasicReferenceID = @pBasicReferenceID

GO